<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
    <style>
        .layui-table-view .layui-table td {
            cursor: pointer;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加</button>
            </div>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="del">删除</a>
        </script>
    </div>
</div>
{include file="public/footer" /}
<script>
    var global_table;
    layui.use(['form', 'table', 'laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate;
        global_table = table;
        table.render({
            elem: '#currentTableId',
            url: '/admin/Active/full_delivery?action=list',
            method: 'post',
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.count, //解析数据长度
                    "data": res.data.data, //解析数据列表
                };
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'amount', title: '充值金币数量', edit: 'number', sort: true,},
                {field: 'give_num', title: '赠送金币数量', edit: 'number', sort: true,},
                {title: '操作', toolbar: '#currentTableBar'}
            ]],
            page: false,
            skin: 'line'
        });
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '满送设置',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/Active/full_delivery?action=addView',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });

        //监听单元格编辑
        table.on('edit(currentTableFilter)', function (obj) {
            var value = obj.value //得到修改后的值
                , data = obj.data //得到所在行所有键值
                , field = obj.field; //得到字段
            $.ajax({
                url: "/admin/Active/full_delivery?action=write",
                type: 'post',
                async: true,
                data: {
                    value: value,
                    id: data.id,
                    field: field
                },
                dataType: 'json',
                success: function (res) {
                    if (res.status) {
                        return;
                    } else {
                        layer.msg(res.msg);
                    }
                }
            });
        });
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        url: "/admin/Active/full_delivery?action=del",
                        type: 'post',
                        async: true,
                        data: {
                            id: data.id
                        },
                        dataType: 'json',
                        success: function (res) {
                            if (res.status) {
                                obj.del();
                                layer.close(index);
                            } else {
                                layer.msg(res.msg);
                            }
                        }
                    });
                });
            }
        });

    });
</script>

</body>
</html>